package com.alawn.framework.core.persistence.mybatis.handler;

import java.time.LocalDateTime;

import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import com.alawn.framework.core.utils.ShiroUtils;
import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;

@Component
public class AuditableEntityHandler implements MetaObjectHandler {

	@Override
	public void insertFill(MetaObject metaObject) {
		this.setFieldValByName("creator", ShiroUtils.getLoginName(), metaObject);
		this.setFieldValByName("operator", ShiroUtils.getLoginName(), metaObject);
		this.setFieldValByName("createdTime", LocalDateTime.now(), metaObject);
		this.setFieldValByName("operationTime", LocalDateTime.now(), metaObject);
	}

	@Override
	public void updateFill(MetaObject metaObject) {
		this.setFieldValByName("operator", ShiroUtils.getLoginName(), metaObject);
		this.setFieldValByName("operationTime", LocalDateTime.now(), metaObject);
	}

}